package com.top.mall.app

import android.app.Application
import androidx.lifecycle.MutableLiveData
import androidx.multidex.MultiDex
import androidx.room.Room
import com.module.lemlin.http.HttpServiceFactory
import com.module.lemlin.owner.OwnerApplication
import com.top.mall.db.AppDatabase
import com.top.mall.entity.CartList
import rxhttp.RxHttpPlugins

class BaseApplication : OwnerApplication() {

    companion object {
        lateinit var INSTANCE: Application

        lateinit var appDatabase: AppDatabase

        private val cartListLiveData = MutableLiveData<MutableList<CartList>>()

        fun getCartListLiveData(): MutableLiveData<MutableList<CartList>> = cartListLiveData

        fun setCartListLiveData(cartList: MutableList<CartList>?) {
            cartListLiveData.postValue(cartList)
        }

        const val SHOP_ID = 15
        const val WAREHOUSE_NO = "01"
    }

    override fun onCreate() {
        super.onCreate()

        //获取Application
        INSTANCE = this

        appDatabase = Room.databaseBuilder(INSTANCE, AppDatabase::class.java, ("topmall.db"))
            .allowMainThreadQueries()
            .build()

        RxHttpPlugins.init(HttpServiceFactory.client().build())
            .setOnParamAssembly {
                it.addHeader("token", SPSConstance.token?:"")
            }.setDebug(true)

        MultiDex.install(this)
    }
}